/*
* test1
*/
package com.pitop.repair.ctrl;

import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import java.util.List;
import java.util.HashMap;

import com.pitop.core.entity.BeanRet;
import com.pitop.core.entity.Page;
import com.pitop.core.tools.redis.RedisUtils;
import com.pitop.repair.entity.RepairStaff;
import com.pitop.repair.service.RepairStaffSV;

/**
 * 维修账户 控制器
 *
 * @author test1
 */
@RestController
@RequestMapping("/repairStaff")
@Slf4j
@Api(value = "维修账户控制器", description = "维修账户控制器")
public class RepairStaffCtrl {

    @Resource
    protected RedisUtils redisUtils;

    @Resource
    private RepairStaffSV repairStaffSV;

    /**
     * 查询RepairStaff一个详情信息
     *
     * @param id
     * @param code 编码
     * @return BeanRet
     */
    @ApiOperation(value = "查询RepairStaff一个详情信息", notes = "查询RepairStaff一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", dataType = "java.lang.Long", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "编码", dataType = "java.lang.String", paramType = "query")
    })
    @GetMapping(value = "/load")
    @ResponseBody
    public RepairStaff load(Long id, String code) {
        if (id == null) {
            return null;
        }
        if (code == null) {
            return null;
        }
        RepairStaff repairStaff = repairStaffSV.load(id, code);
        log.info(JSON.toJSONString(repairStaff));
        return repairStaff;
    }


    /**
     * 根据条件id查询RepairStaff一个详情信息
     *
     * @param id
     * @return BeanRet
     */
    @ApiOperation(value = "查询RepairStaff一个详情信息", notes = "查询RepairStaff一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", dataType = "java.lang.Long", paramType = "path")
    })
    @GetMapping(value = "/load/id/{id}")
    @ResponseBody
    public RepairStaff loadById(@PathVariable Long id) {
        if (id == null) {
            return null;
        }
        RepairStaff repairStaff = repairStaffSV.loadById(id);
        log.info(JSON.toJSONString(repairStaff));
        return repairStaff;
    }

    /**
     * 根据条件code查询RepairStaff一个详情信息
     *
     * @param code 编码
     * @return BeanRet
     */
    @ApiOperation(value = "查询RepairStaff一个详情信息", notes = "查询RepairStaff一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "code", value = "编码", dataType = "java.lang.String", paramType = "path")
    })
    @GetMapping(value = "/load/code/{code}")
    @ResponseBody
    public RepairStaff loadByCode(@PathVariable String code) {
        if (code == null) {
            return null;
        }
        RepairStaff repairStaff = repairStaffSV.loadByCode(code);
        log.info(JSON.toJSONString(repairStaff));
        return repairStaff;
    }


    /**
     * 查询RepairStaff信息集合
     *
     * @return 分页对象
     */
    @ApiOperation(value = "查询RepairStaff信息集合", notes = "查询RepairStaff信息集合")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
            @ApiImplicitParam(name = "createTimeBegin", value = "创建时间", paramType = "query"),
            @ApiImplicitParam(name = "createTimeEnd", value = "创建时间", paramType = "query"),
            @ApiImplicitParam(name = "updateTimeBegin", value = "更新时间", paramType = "query"),
            @ApiImplicitParam(name = "updateTimeEnd", value = "更新时间", paramType = "query")
    })
    @PostMapping(value = "/list")
    @ResponseBody
    public List<RepairStaff> list(@RequestBody @ApiIgnore RepairStaff repairStaff, Integer curPage, Integer pageSize) {
        Page<RepairStaff> page = new Page<RepairStaff>(pageSize, curPage);
        List<RepairStaff> repairStaffs = repairStaffSV.list(repairStaff, page.genRowStart(), page.getPageSize());
        int total = repairStaffSV.count(repairStaff);
        page.setTotalRow(total);
        log.info(JSON.toJSONString(page));
        return repairStaffs;
    }


    /**
     * 查询RepairStaff信息集合
     *
     * @return 分页对象
     */
    @ApiOperation(value = "查询RepairStaff信息集合", notes = "查询RepairStaff信息集合")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "编码", paramType = "query")
    })
    @GetMapping(value = "/list/by")
    @ResponseBody
    public List<RepairStaff> listByPk(Long id, String code, Integer curPage, Integer pageSize) {
        Page<RepairStaff> page = new Page<RepairStaff>(pageSize, curPage);
        List<RepairStaff> repairStaffs = repairStaffSV.list(id, code, page.genRowStart(), page.getPageSize());
        int total = repairStaffSV.count(id, code);
        page.setTotalRow(total);
        log.info(JSON.toJSONString(page));
        return repairStaffs;
    }

    /**
     * 统计RepairStaff信息数量根据主键
     *
     * @return 总条数
     */
    @ApiOperation(value = " 统计RepairStaff信息数量根据主键", notes = " 统计RepairStaff信息数量根据主键")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "编码", paramType = "query")
    })
    @GetMapping(value = "/count/by")
    @ResponseBody
    public Integer count(Long id, String code) {
        return repairStaffSV.count(id, code);
    }

    /**
     * 统计RepairStaff信息数量
     *
     * @return 总条数
     */
    @ApiOperation(value = "统计RepairStaff信息数量", notes = "统计RepairStaff信息数量")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "编码", paramType = "query"),
            @ApiImplicitParam(name = "email", value = "邮箱", paramType = "query"),
            @ApiImplicitParam(name = "password", value = "密码 md5 加密", paramType = "query"),
            @ApiImplicitParam(name = "jobnumber", value = "工号 0000四位格式", paramType = "query"),
            @ApiImplicitParam(name = "lastName", value = "姓", paramType = "query"),
            @ApiImplicitParam(name = "firstName", value = "名", paramType = "query"),
            @ApiImplicitParam(name = "gender", value = "性别：男 Male，女 Female，其他 Other", paramType = "query"),
            @ApiImplicitParam(name = "avatar", value = "头像", paramType = "query"),
            @ApiImplicitParam(name = "countryCode", value = "国家代码", paramType = "query"),
            @ApiImplicitParam(name = "language", value = "语言", paramType = "query"),
            @ApiImplicitParam(name = "timezone", value = "所在时区", paramType = "query"),
            @ApiImplicitParam(name = "state", value = "状态：激活[Activate]，冻结[Frozen]，删除[Delete]", paramType = "query"),
            @ApiImplicitParam(name = "createTime", value = "创建时间", paramType = "query"),
            @ApiImplicitParam(name = "updateTime", value = "更新时间", paramType = "query")
    })
    @PostMapping(value = "/count")
    @ResponseBody
    public Integer count(@RequestBody RepairStaff repairStaff) {
        return repairStaffSV.count(repairStaff);
    }


    /**
     * 创建RepairStaff
     *
     * @return BeanRet
     */
    @ApiOperation(value = "创建RepairStaff", notes = "创建RepairStaff")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "email", value = "邮箱", paramType = "query"),
            @ApiImplicitParam(name = "password", value = "密码 md5 加密", paramType = "query"),
            @ApiImplicitParam(name = "jobnumber", value = "工号 0000四位格式", paramType = "query"),
            @ApiImplicitParam(name = "lastName", value = "姓", paramType = "query"),
            @ApiImplicitParam(name = "firstName", value = "名", paramType = "query"),
            @ApiImplicitParam(name = "gender", value = "性别：男 Male，女 Female，其他 Other", paramType = "query"),
            @ApiImplicitParam(name = "avatar", value = "头像", paramType = "query"),
            @ApiImplicitParam(name = "countryCode", value = "国家代码", paramType = "query"),
            @ApiImplicitParam(name = "language", value = "语言", paramType = "query"),
            @ApiImplicitParam(name = "timezone", value = "所在时区", paramType = "query"),
            @ApiImplicitParam(name = "state", value = "状态：激活[Activate]，冻结[Frozen]，删除[Delete]", paramType = "query"),
            @ApiImplicitParam(name = "createTime", value = "创建时间", paramType = "query"),
            @ApiImplicitParam(name = "updateTime", value = "更新时间", paramType = "query")
    })
    @PostMapping("/build")
    @ResponseBody
    public RepairStaff build(@RequestBody @ApiIgnore RepairStaff repairStaff) {
        repairStaffSV.save(repairStaff);
        return repairStaff;
    }


    /**
     * 修改RepairStaff
     *
     * @return BeanRet
     */
    @ApiOperation(value = "修改RepairStaff", notes = "修改RepairStaff")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "编码", paramType = "query"),
            @ApiImplicitParam(name = "email", value = "邮箱", paramType = "query"),
            @ApiImplicitParam(name = "password", value = "密码 md5 加密", paramType = "query"),
            @ApiImplicitParam(name = "jobnumber", value = "工号 0000四位格式", paramType = "query"),
            @ApiImplicitParam(name = "lastName", value = "姓", paramType = "query"),
            @ApiImplicitParam(name = "firstName", value = "名", paramType = "query"),
            @ApiImplicitParam(name = "gender", value = "性别：男 Male，女 Female，其他 Other", paramType = "query"),
            @ApiImplicitParam(name = "avatar", value = "头像", paramType = "query"),
            @ApiImplicitParam(name = "countryCode", value = "国家代码", paramType = "query"),
            @ApiImplicitParam(name = "language", value = "语言", paramType = "query"),
            @ApiImplicitParam(name = "timezone", value = "所在时区", paramType = "query"),
            @ApiImplicitParam(name = "state", value = "状态：激活[Activate]，冻结[Frozen]，删除[Delete]", paramType = "query"),
            @ApiImplicitParam(name = "createTime", value = "创建时间", paramType = "query"),
            @ApiImplicitParam(name = "updateTime", value = "更新时间", paramType = "query")
    })
    @PutMapping("/modify")
    @ResponseBody
    public RepairStaff modify(@RequestBody @ApiIgnore RepairStaff repairStaff) {
        repairStaffSV.modify(repairStaff);
        return repairStaff;
    }

    /**
     * 删除RepairStaff
     *
     * @return BeanRet
     */
    @ApiOperation(value = "删除RepairStaff", notes = "删除RepairStaff")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "编码", paramType = "query")
    })
    @DeleteMapping("/delete")
    @ResponseBody
    public BeanRet delete(Long id, String code) {
        repairStaffSV.delete(id, code);
        return BeanRet.create(true, "删除RepairStaff成功");
    }

}
